package org.oschina.plugin.topic;

import org.oschina.Constants;
import org.oschina.helper.topic.AbstractTopicListener;
import org.oschina.plugin.PluginHelper;
import org.oschina.plugin.bean.PluginRemoveSyncBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 插件移除同步处理
 */
@Component
public class PluginRemoveSyncTopic extends AbstractTopicListener {

	private final static Logger logger=LoggerFactory.getLogger(PluginRemoveSyncTopic.class);
	
	@Autowired
	private PluginHelper pluginHelper;

	@Override
	public String getKey()
	{
		return Constants.TOPIC_PLUGIN_REMOVE_SYNC;
	}

	@Override
	public Class getType()
	{
		return PluginRemoveSyncBean.class;
	}

	@Override
	public synchronized void handle(Object message)
	{
		PluginRemoveSyncBean bean=(PluginRemoveSyncBean) message;
		pluginHelper.remove(bean.getId());
		logger.info("ID为 '{}' 的插件移除同步成功",bean.getId());
	}
}